package com.bitrate.dagger.server.mqtt.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.bitrate.dagger.sdk.mqtt.dto.MqttPushDTO;
import com.bitrate.dagger.sdk.mqtt.enums.MqttPushResponse;
import com.bitrate.dagger.server.mqtt.service.MqttService;

@RequestMapping("/mqtt-api")
@RestController
public class MqttController {

	@Autowired
	private MqttService mqttService;

	@PostMapping("/publish")
	public String publish(@RequestBody MqttPushDTO mqttPushDTO) {
		String clientId = mqttPushDTO.getClientId();
		String topic = mqttPushDTO.getTopic();
		String message = mqttPushDTO.getMessage();
		Boolean flag = mqttService.publish(clientId, topic, message);
		return flag ? MqttPushResponse.SUCCESS.getResult() : MqttPushResponse.FAIL.getResult();
	}

}
